import { NS, Constants } from './base';

/**
 * 模拟节点数组
 * @param max 最大模拟节点数
 * @param compact 是否紧凑节点
 * @returns 节点集合
 */
export function mockNodes(max = 20, weight = 0) {
  let index = 0;
  let count = 0;
  const nodes: NS.XNode[] = [];
  function mockNode() {
    let type = (index === 0 ? Constants.Serial : Math.floor(Math.random() * (3 + weight))) as NS.NodeType;
    if (type >= 2) type = 2;
    const name = ['S', 'P', 'N'][type] + index++;
    const node: NS.XNode = new MockXNode(type, name);
    nodes.push(node);
    if (type === Constants.Node) {
      count++;
      return node;
    }
    const len = Math.floor(Math.random() * 7) + 3;
    for (let i = 0; i < len; i++) {
      if (count >= max) break;
      node.children!.push(mockNode());
    }
    return node;
  }
  mockNode();
  while (max > count) {
    nodes[0].children?.push(mockNode());
  }
  return nodes;
}


/** 模拟基础数据节点 */
export class MockXNode implements NS.XNode {
  type: NS.NodeType;
  name: string;
  children: MockXNode[] = [];

  // 计算出来的值
  size: NS.Size = [0, 0, 0, 0, 0];
  position: [number, number] = [0, 0];
  constructor(type: NS.NodeType, name: string) {
    this.type = type;
    this.name = name;
  }
}



